package mrusanov.battle

import mrusanov.terrain.TerrainType
import util.Random

class PlayersDuelRound(arena:MiniArena, first:PlayerState, second:PlayerState, rand:Random = new Random()) {
  val terrain = arena.terrain

  def fightRound():List[AttackInfo] = {
    val attacks = generatePlayersDuelAttacks
    var result = List[AttackInfo]()
    attacks map ({ a =>
      if (bothAreAlive) {
        result :+= a.executeAttack()
      }
    })

    result
  }

  private def bothAreAlive = first.alive && second.alive

  private [battle] def generatePlayersDuelAttacks:List[PlayersDuelAttack] = {
    val players =
    rand.nextBoolean() match {
       case true =>  (first, second)
       case false => (second, first)
    }

    List(new PlayersDuelAttack(players._1, players._2, arena),
      new PlayersDuelAttack(players._2, players._1, arena))
  }

}
